---
--类名: BattleMapModel.lua
--创建日期: 2018-9-6
--创建人: 宋建邦
--功能描述:领地争夺战地图数据
--修改内容:
--修改日期:
--修改人:
--修改备注:

local BattleMapModel = class("BattleMapModel")

function BattleMapModel:ctor()
end

function BattleMapModel:read(msg)
    self._msg = msg
    self.worldMapModel = app:getInst("WorldMapModel") 

    self.townInfos = {}
    self.hTownInfos = {}
    for i, v in ipairs(msg.infos) do 
        local ti = {
            data = v,
            config = self.worldMapModel._zoneDict[v.id],
            getGuildName = function(self)
                if self.data and self.data.owner and self.data.owner.info
                and self.data.owner.info.guildName 
                and string.len(self.data.owner.info.guildName) > 0 then
                    return self.data.owner.info.guildName
                end
            end,
            getFlagInfo = function(self)
                if self.data and self.data.owner and self.data.owner.info
                and self.data.owner.info.guildName 
                and string.len(self.data.owner.info.guildName) > 0 then
                    return self.data.owner.info
                end
            end,
            getStartWeekDay = function(self, forceNext)
                local cfgd = self.config._conf.openDate
                local curd = os.date("*t", app.session:getServerTime()).wday
                curd = curd - 1
                if curd == 0 then curd = 7 end
                local ds = string.split(cfgd, "|")
                local nextweek = true
                local today = false
                local nextday = 0

                for i, v in ipairs(ds) do
                    if curd < checknumber(v) then
                        nextweek = false
                        nextday = checknumber(v)
                        break
                    elseif curd == checknumber(v) then
                        today = true
                    end
                end
                local ret = ""
                local transn = {L("lua_code_text_286"), L("lua_code_text_22"), L("lua_code_text_247"), L("lua_code_text_375"), L("lua_code_text_24"), L("lua_code_text_292"), L("lua_code_text_483")}
                if nextweek then
                    ret = L("lua_code_text_29")..transn[checknumber(ds[1])]
                else
                    ret = L("lua_code_text_334")..transn[nextday]
                end

                if today and not forceNext then
                    ret = L("lua_code_text_266")
                end
                return ret, today
            end
        }
        self.hTownInfos[ti.data.id] = ti
        table.insert(self.townInfos, ti)
    end

    table.sort(self.townInfos, function(a, b)
        return checknumber(a.config._conf.warmapList) < checknumber(b.config._conf.warmapList)
    end)

    -- dump(self._msg, "battle map info")
end

return BattleMapModel